import { defineStore } from 'pinia'
import { ref } from 'vue'

export const userWebStore = defineStore(
  'web-socket',
  () => {
    const onOpen = () => {

    }
    const onClose = () => {

    }
    //所有在线人员列表
    const onlineList = ref({})
    const setOnline = (list) => {
        onlineList.value = {}
        list.forEach(key => {
            onlineList.value[key] = 0;
        })
    }
    const removeOnline = () => {
        onlineList.value = {}
    }
    //所有好友列表
    const friendList = ref([])
    const setFriend = (list) => {
        friendList.value = {}
        list.forEach(key => {
          friendList.value[key.id] = 0;
        })
    }
    const removeFriend = () => {
        friendList.value = []
    }
    //当前对方用户信息
    const otherInfo = ref({})
    const setOtherInfo = (list) => {
        otherInfo.value = {}
        otherInfo.value = list;
    }
    const removeInfo = () => {
        otherInfo.value = {}
    }
    return {
      onOpen,
      onClose,
      onlineList,
      friendList,
      setOnline,
      removeOnline,
      setFriend,
      removeFriend,
      otherInfo,
      setOtherInfo,
      removeInfo
    }
  },
  {
    persist: true
  }
)
